package com.aaa.demo11;

import java.util.*;

/**
 * @author ${崔灿}
 * @date 2022/11/03 19:44
 **/

public class Test03 {
    public static void main(String[] args) {
        List<Student> list=new ArrayList<>();
        list.add(new Student("崔灿",34));
        list.add(new Student("崔灿1",22));
        list.add(new Student("崔灿2",44));
        list.add(new Student("崔灿3",66));
//        Comparator<Student> comparator = new Comparator<Student>(){
//
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge()-o2.getAge();
//            }
//        };

        Comparator<Student> comparator = (o1,o2)->{
            return o1.getAge()-o2.getAge();
        };
        Collections.sort(list, comparator);
        System.out.println(list);
    }
}
class Student{
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
